import { Component, OnInit } from '@angular/core';

import { HomeService } from './home.service'

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.less']
})
export class HomeComponent implements OnInit {

  public title: string = 'Home组件';
  public titleMsg: string = '这个是title信息';
  public pngUrl: string;
  public temp: string = '<h1>哈哈哈</h1>';
  public flag: boolean = true
  public status: number = 0
  public inputWords: string // 双向数据绑定的值
  public todayDate: Date = new Date()
  public arr: Array<any> = [
    {name: '张三'},
    {name: '李四'},
    {name: '王五'},
    {name: '赵六'}
  ]
  public user: any = {
    name: '张三',
    age: 22
  }
  // 定义对象类型
  public userMsg: {[key: string]: any} = {
    name: '张无忌',
    age: 20
  }

  public listData: Array<any> = []

  constructor(public homeSV: HomeService) { }

  ngOnInit(): void {
    this.pngUrl = 'https://img2.baidu.com/it/u=3228549874,2173006364&fm=26&fmt=auto&gp=0.jpg'
  }

  getList(): void {
    this.homeSV.getList().subscribe(res => {
      console.log('%c getRes---', 'color: deeppink', res)
      this.listData = res.result
    })
  }

  getJsonpData() {
    this.homeSV.getListJsonp().subscribe(res => {
      console.log('%c getRes---', 'color: deeppink', res)
      this.listData = res.result
    })
  }

  getDate(): string {
    console.log(1111)
    const date = new Date()
    const year = date.getFullYear()
    console.log('year---', year)
    return year + ''
  }
  keyUp(e): void {
    console.log(e)
    console.log(e.keyCode)
    console.log(e.target.value)
  }
  changeInputWords(): void {
    this.inputWords = this.inputWords + 'abc'
  }

}
